#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 5005
int n, l, w, cnt, vis[maxn];
struct node
{
    int l, w;
    node(int l = -1, int w = -1) : l(l), w(w){};
    bool operator<(node p) const
    {
        if (w == p.w)
            return l > p.l;
        return w > p.w;
    }
};
node arr[maxn];
int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> l >> w;
        arr[i].l = l, arr[i].w = w;
    }
    sort(arr, arr + maxn);
    l = arr[0].l, w = arr[0].w;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (vis[j] == 0 && arr[j].l <= l && arr[j].w <= w)
            {
                vis[j] = 1;
                l = arr[j].l, w = arr[j].w;
            }
        }
        if (vis[i] == 0 && (arr[i].l > l || arr[i].w > w))
        {
            cnt++;
            l = arr[i].l, w = arr[i].w;
        }
    }
    cout << cnt + 1 << endl;
    return 0;
}